import React, { useState, useCallback } from "react";

function Callback() {
  const [name, setName] = useState("gqg");
  const [age, setAge] = useState(10);
  let age2 = useCallback(() => {
    console.log("2222");
    return age < 18 ? "未成年" : "成年";
  }, [age < 18]);
  return (
    <div>
      <h4>性名：{name}</h4>
      <h4>年龄：{age}</h4>
      <h4>年龄阶段：{age2()}</h4>
      <button
        onClick={() => {
          setAge(age + 2);
        }}
      >
        长大
      </button>
    </div>
  );
}
export default Callback;
